public class Hanoi {
    public static void main(String[] args) {
        String x = "X";
        String y = "Y";
        String z = "Z";
        hanoi(3, x, y, z);
    }

    private static void hanoi(int level, String begin, String mid, String end) {
        if (level == 1) {
            System.out.println(begin + "->" + end);
        } else {
            hanoi(level - 1, begin, end, mid);
            System.out.println(begin + "->" + end);
            hanoi(level - 1, mid, begin, end);
        }
    }
}